package cn.com.jslh.boarpro.main.view;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.SearchView;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.com.jslh.boarpro.R;
import cn.com.jslh.boarpro.main.contract.ChosePersonContract;
import cn.com.jslh.boarpro.main.presenter.ChosePersonPresenterImpl;

public class ChosePersonActivity extends AppCompatActivity implements ChosePersonContract.View {

    @BindView(R.id.searchview)
    SearchView searchview;
    @BindView(R.id.recycleview)
    RecyclerView recycleview;
    private ChosePersonContract.Presenter presenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_chose_person);
        ButterKnife.bind(this);
        new ChosePersonPresenterImpl(this,this);

        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this,LinearLayoutManager.VERTICAL,false);
        recycleview.setLayoutManager(linearLayoutManager);
        presenter.bindRV(recycleview);
        presenter.start();

        searchview.setIconifiedByDefault(true);
        searchview.setFocusable(true);
        searchview.setIconified(false);
        searchview.requestFocusFromTouch();

        searchview.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextSubmit(String query) {
                presenter.search(query);
                return false;
            }

            @Override
            public boolean onQueryTextChange(String newText) {
                presenter.search(newText);
                return false;
            }
        });
    }

    @Override
    public void setPresenter(ChosePersonContract.Presenter presenter) {
        this.presenter = presenter;
    }

    @Override
    public void chosePerson(String pid, String pname) {
        Intent intent = new Intent();
        intent.putExtra("pid",pid);
        intent.putExtra("pname",pname);
        setResult(100,intent);
        ChosePersonActivity.this.finish();
    }
}
